$(function () {

    $('#login').validate({

        rules: {
             username: {
                 required:true,
                 minlength: 6,
                 maxlength: 16
                    },

            password: {
                required:true,
                minlength: 6,
                maxlength: 16
                     }
            },

            messages:{
                username:{
                    required:'请填写用户名信息',
                    minlength:'最少6个字符',
                    maxlength:'最多16个字符'
                }
            },
            submitHandler (form){
                const info = $(form).serialize()
                // console.log(info)

                $.post('../php/denglu.php',info , null , 'json' ).then(res => {

                    console.log(res)

                    if(res.code === 0){
                        $('.span').removeClass('hide')
                        console.log(123)
                    } else if (res.code === 1){
                        console.log(456)

                        setCookie('nickname', res.nickname)

                        window.location.href = '../html/index.html'
                    }

                }) 
            }

    })

})
